<template>
  <el-dialog
    v-loading="loading"
    :visible.sync="dialog"
    :close-on-click-modal="false"
    title="审核详情"
    width="85%"
  >
    <div style="padding-top:5px">
      <div style="float:right;margin-bottom:5px;">
        <el-button size="mini" type="primary" icon="el-icon-circle-check" round @click="batchAgree">批量同意</el-button>
        <el-button size="mini" type="primary" icon="el-icon-circle-close" round @click="batchReject">批量驳回</el-button>
      </div>
      <el-table ref="itemTab" :data="data" stripe size="small" border style="width: 100%;" @header-dragend="colChange">
        <el-table-column :show-overflow-tooltip="true" label="商品号" prop="itemNbr" :width="colWidths.itemNbr" />
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="商品说明1" prop="buyerItem1Desc" :width="colWidths.buyerItem1Desc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItem1Desc !== scope.row.vendorItem1Desc ? 'color:#fc1111' : ''">{{ scope.row.buyerItem1Desc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="商品说明1" prop="vendorItem1Desc" :width="colWidths.vendorItem1Desc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItem1Desc !== scope.row.vendorItem1Desc ? 'color:#fc1111' : ''">{{ scope.row.vendorItem1Desc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="较长商品说明" prop="buyerItem1DescLength" :width="colWidths.buyerItem1DescLength">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItem1DescLength !== scope.row.vendorItem1DescLength ? 'color:#fc1111' : ''">{{ scope.row.buyerItem1DescLength }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="较长商品说明" prop="vendorItem1DescLength" :width="colWidths.vendorItem1DescLength">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItem1DescLength !== scope.row.vendorItem1DescLength ? 'color:#fc1111' : ''">{{ scope.row.vendorItem1DescLength }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="货架2/规格" prop="buyerShlflbl2SizeDesc" :width="colWidths.buyerShlflbl2SizeDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl2SizeDesc !== scope.row.vendorShlflbl2SizeDesc ? 'color:#fc1111' : ''">{{ scope.row.buyerShlflbl2SizeDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="货架2/规格" prop="vendorShlflbl2SizeDesc" :width="colWidths.vendorShlflbl2SizeDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl2SizeDesc !== scope.row.vendorShlflbl2SizeDesc ? 'color:#fc1111' : ''">{{ scope.row.vendorShlflbl2SizeDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="规格型号" prop="buyerShlflbl3SizeDesc" :width="colWidths.buyerShlflbl3SizeDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl3SizeDesc !== scope.row.vendorShlflbl3SizeDesc ? 'color:#fc1111' : ''">{{ scope.row.buyerShlflbl3SizeDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="规格型号" prop="vendorShlflbl3SizeDesc" :width="colWidths.vendorShlflbl3SizeDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl3SizeDesc !== scope.row.vendorShlflbl3SizeDesc ? 'color:#fc1111' : ''">{{ scope.row.vendorShlflbl3SizeDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="产地" prop="buyerMdsDesc" :width="colWidths.buyerMdsDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerMdsDesc !== scope.row.vendorMdsDesc ? 'color:#fc1111' : ''">{{ scope.row.buyerMdsDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="产地" prop="vendorMdsDesc" :width="colWidths.vendorMdsDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerMdsDesc !== scope.row.vendorMdsDesc ? 'color:#fc1111' : ''">{{ scope.row.vendorMdsDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="供应商之商品代码" prop="buyerVendorStockId" :width="colWidths.buyerVendorStockId">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVendorStockId !== scope.row.vendorStockId ? 'color:#fc1111' : ''">{{ scope.row.buyerVendorStockId }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="供应商之商品代码" prop="vendorStockId" :width="colWidths.vendorStockId">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVendorStockId !== scope.row.vendorStockId ? 'color:#fc1111' : ''">{{ scope.row.vendorStockId }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="条码" prop="buyerUpcNbr" :width="colWidths.buyerUpcNbr">
            <template slot-scope="scope">
              <span :style="scope.row.buyerUpcNbr !== scope.row.vendorUpcNbr ? 'color:#fc1111' : ''">{{ scope.row.buyerUpcNbr }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="条码" prop="vendorUpcNbr" :width="colWidths.vendorUpcNbr">
            <template slot-scope="scope">
              <span :style="scope.row.buyerUpcNbr !== scope.row.vendorUpcNbr ? 'color:#fc1111' : ''">{{ scope.row.vendorUpcNbr }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="进项税" prop="buyerVatIn" :width="colWidths.buyerVatIn">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVatIn !== scope.row.vendorVatIn ? 'color:#fc1111' : ''">{{ scope.row.buyerVatIn }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="进项税" prop="vendorVatIn" :width="colWidths.vendorVatIn">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVatIn !== scope.row.vendorVatIn ? 'color:#fc1111' : ''">{{ scope.row.vendorVatIn }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="配色配码" prop="buyerColorMatch" :width="colWidths.buyerColorMatch">
            <template slot-scope="scope">
              <span :style="scope.row.buyerColorMatch !== scope.row.vendorColorMatch ? 'color:#fc1111' : ''">{{ scope.row.buyerColorMatch }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="配色配码" prop="vendorColorMatch" :width="colWidths.vendorColorMatch">
            <template slot-scope="scope">
              <span :style="scope.row.buyerColorMatch !== scope.row.vendorColorMatch ? 'color:#fc1111' : ''">{{ scope.row.vendorColorMatch }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="货架1/颜色" prop="buyerShlflbl1ColrDesc" :width="colWidths.buyerShlflbl1ColrDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl1ColrDesc !== scope.row.vendorShlflbl1ColrDesc ? 'color:#fc1111' : ''">{{ scope.row.buyerShlflbl1ColrDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="货架1/颜色" prop="vendorShlflbl1ColrDesc" :width="colWidths.vendorShlflbl1ColrDesc">
            <template slot-scope="scope">
              <span :style="scope.row.buyerShlflbl1ColrDesc !== scope.row.vendorShlflbl1ColrDesc ? 'color:#fc1111' : ''">{{ scope.row.vendorShlflbl1ColrDesc }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="原包高度" prop="buyerVnpkHeightQty" :width="colWidths.buyerVnpkHeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVnpkHeightQty !== scope.row.vendorVnpkHeightQty ? 'color:#fc1111' : ''">{{ scope.row.buyerVnpkHeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="原包高度" prop="vendorVnpkHeightQty" :width="colWidths.vendorVnpkHeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVnpkHeightQty !== scope.row.vendorVnpkHeightQty ? 'color:#fc1111' : ''">{{ scope.row.vendorVnpkHeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="原包宽度" prop="buyerVnpkWidthQty" :width="colWidths.buyerVnpkWidthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVnpkWidthQty !== scope.row.vendorVnpkWidthQty ? 'color:#fc1111' : ''">{{ scope.row.buyerVnpkWidthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="原包宽度" prop="vendorVnpkWidthQty" :width="colWidths.vendorVnpkWidthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVnpkWidthQty !== scope.row.vendorVnpkWidthQty ? 'color:#fc1111' : ''">{{ scope.row.vendorVnpkWidthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="原包深度" prop="buyerVnpkLengthQty" :width="colWidths.buyerVnpkLengthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVnpkLengthQty !== scope.row.vendorVnpkLengthQty ? 'color:#fc1111' : ''">{{ scope.row.buyerVnpkLengthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="原包深度" prop="vendorVnpkLengthQty" :width="colWidths.vendorVnpkLengthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVnpkLengthQty !== scope.row.vendorVnpkLengthQty ? 'color:#fc1111' : ''">{{ scope.row.vendorVnpkLengthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="原包重量" prop="buyerVnpkWeightQty" :width="colWidths.buyerVnpkWeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVnpkWeightQty !== scope.row.vendorVnpkWeightQty ? 'color:#fc1111' : ''">{{ scope.row.buyerVnpkWeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="原包重量" prop="vendorVnpkWeightQty" :width="colWidths.vendorVnpkWeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerVnpkWeightQty !== scope.row.vendorVnpkWeightQty ? 'color:#fc1111' : ''">{{ scope.row.vendorVnpkWeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="仓包高度" prop="buyerWhpkHeightQty" :width="colWidths.buyerWhpkHeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerWhpkHeightQty !== scope.row.vendorWhpkHeightQty ? 'color:#fc1111' : ''">{{ scope.row.buyerWhpkHeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="仓包高度" prop="vendorWhpkHeightQty" :width="colWidths.vendorWhpkHeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerWhpkHeightQty !== scope.row.vendorWhpkHeightQty ? 'color:#fc1111' : ''">{{ scope.row.vendorWhpkHeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="仓包宽度" prop="buyerWhpkWidthQty" :width="colWidths.buyerWhpkWidthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerWhpkWidthQty !== scope.row.vendorWhpkWidthQty ? 'color:#fc1111' : ''">{{ scope.row.buyerWhpkWidthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="仓包宽度" prop="vendorWhpkWidthQty" :width="colWidths.vendorWhpkWidthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerWhpkWidthQty !== scope.row.vendorWhpkWidthQty ? 'color:#fc1111' : ''">{{ scope.row.vendorWhpkWidthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="仓包深度" prop="buyerWhpkLengthQty" :width="colWidths.buyerWhpkLengthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerWhpkLengthQty !== scope.row.vendorWhpkLengthQty ? 'color:#fc1111' : ''">{{ scope.row.buyerWhpkLengthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="仓包深度" prop="vendorWhpkLengthQty" :width="colWidths.vendorWhpkLengthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerWhpkLengthQty !== scope.row.vendorWhpkLengthQty ? 'color:#fc1111' : ''">{{ scope.row.vendorWhpkLengthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="仓包重量" prop="buyerWhpkWeightQty" :width="colWidths.buyerWhpkWeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerWhpkWeightQty !== scope.row.vendorWhpkWeightQty ? 'color:#fc1111' : ''">{{ scope.row.buyerWhpkWeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="仓包重量" prop="vendorWhpkWeightQty" :width="colWidths.vendorWhpkWeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerWhpkWeightQty !== scope.row.vendorWhpkWeightQty ? 'color:#fc1111' : ''">{{ scope.row.vendorWhpkWeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="商品高度" prop="buyerItemHeightQty" :width="colWidths.buyerItemHeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItemHeightQty !== scope.row.vendorItemHeightQty ? 'color:#fc1111' : ''">{{ scope.row.buyerItemHeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="商品高度" prop="vendorItemHeightQty" :width="colWidths.vendorItemHeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItemHeightQty !== scope.row.vendorItemHeightQty ? 'color:#fc1111' : ''">{{ scope.row.vendorItemHeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="商品宽度" prop="buyerItemWidthQty" :width="colWidths.buyerItemWidthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItemWidthQty !== scope.row.vendorItemWidthQty ? 'color:#fc1111' : ''">{{ scope.row.buyerItemWidthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="商品宽度" prop="vendorItemWidthQty" :width="colWidths.vendorItemWidthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItemWidthQty !== scope.row.vendorItemWidthQty ? 'color:#fc1111' : ''">{{ scope.row.vendorItemWidthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="商品深度" prop="buyerItemLengthQty" :width="colWidths.buyerItemLengthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItemLengthQty !== scope.row.vendorItemLengthQty ? 'color:#fc1111' : ''">{{ scope.row.buyerItemLengthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="商品深度" prop="vendorItemLengthQty" :width="colWidths.vendorItemLengthQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItemLengthQty !== scope.row.vendorItemLengthQty ? 'color:#fc1111' : ''">{{ scope.row.vendorItemLengthQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="采购">
          <el-table-column :show-overflow-tooltip="true" label="商品重量" prop="buyerItemWeightQty" :width="colWidths.buyerItemWeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItemWeightQty !== scope.row.vendorItemWeightQty ? 'color:#fc1111' : ''">{{ scope.row.buyerItemWeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商">
          <el-table-column :show-overflow-tooltip="true" label="商品重量" prop="vendorItemWeightQty" :width="colWidths.vendorItemWeightQty">
            <template slot-scope="scope">
              <span :style="scope.row.buyerItemWeightQty !== scope.row.vendorItemWeightQty ? 'color:#fc1111' : ''">{{ scope.row.vendorItemWeightQty }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="附件" prop="filePath" :width="colWidths.filePath">
          <template slot-scope="scope">
            <i v-if="scope.row.filePath" class="el-icon-picture" style="font-size:23px;margin-right: 3px;" @click="previewFile(scope.row.filePath)" />
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="提交时间" prop="updatedTime" :width="colWidths.updatedTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updatedTime) }}</span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <el-pagination
        :total="total"
        :current-page.sync="currentPage"
        :page-sizes="[10,50,100,500]"
        style="margin-top: 8px;"
        layout="total, prev, pager, next, sizes"
        @size-change="sizeChange"
        @current-change="pageChange"
      />
    </div>
  </el-dialog>
</template>

<script>
import { parseTime } from '@/utils/index'
import { Message } from 'element-ui'
import initData from '@/utils/initData'
import { batchItemFileAuditAgree, batchItemFileAuditReject } from '@/api/change-item'
import { previewFile } from '@/utils/item'

export default {
  mixins: [initData],
  props: {
    parent: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      loading: false,
      dialog: false,
      batchRecordId: '',
      changeType: 1
    }
  },
  methods: {
    parseTime,
    previewFile,
    beforeInit() {
      this.url = '/change-item/itemFileAuditList'
      this.params.pageNum = this.page
      this.params.pageSize = this.size
      this.params.batchRecordId = this.batchRecordId
      this.params.changeType = this.changeType
      return true
    },
    // 查询
    toQuery() {
      this.page = 0
      this.currentPage = 1
      this.init()
    },
    // 批量同意触发
    batchAgree() {
      this.$confirm('确认审核通过该批item信息？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        batchItemFileAuditAgree(this.batchRecordId, this.changeType).then(res => {
          this.parent.toQuery()
          Message({
            message: '审核完成。',
            type: 'success',
            duration: 3 * 1000
          })
          this.loading = false
          this.dialog = false
        }, error => {
          console.log(error)
          this.loading = false
        })
      })
    },
    // 批量审核驳回
    batchReject() {
      this.$prompt('请输入驳回原因', '确认审核驳回该批item信息？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValidator: this.rejectRemarkValidator,
        type: 'warning'
      }).then((rejectRemark) => {
        this.loading = true
        batchItemFileAuditReject(this.batchRecordId, this.changeType, rejectRemark.value).then(res => {
          this.parent.toQuery()
          Message({
            message: '审核完成。',
            type: 'success',
            duration: 3 * 1000
          })
          this.loading = false
          this.dialog = false
        }, error => {
          console.log(error)
          this.loading = false
        })
      })
    },
    rejectRemarkValidator(val) {
      if (!val) {
        return '请填写驳回原因'
      } else if (val.length > 500) {
        return '驳回原因长度为1-500'
      }
      return true
    }
  }
}
</script>
